// 云函数入口文件
const cloud = require('wx-server-sdk')
const Mock = require('mockjs');
const {list} = Mock.mock({
  "list|30": [
    {
      "image": "@image(100x100,@color)",
      "title": "@ctitle(6,10)",
      "price|1-20": 1
    }
  ]
})

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const result = await cloud.database().collection('mock_product').add({
    data: list
  })
  return {
    event,
    result,
    openid: wxContext.OPENID,
    appid: wxContext.APPID,
    unionid: wxContext.UNIONID,
  }
}